<template>
  <div>
    <JADP-table :data="list" height="380px">
      <el-table-column label="姓名" prop="stuName"></el-table-column>
      <el-table-column label="身份证" prop="idCard"></el-table-column>
      <el-table-column label="单位" prop="company"></el-table-column>
      <el-table-column label="得分" prop="score" sortable></el-table-column>
      <el-table-column label="正确率" prop="correctRate" sortable>
        <template v-slot="{ row }">
          {{ row.correctRate | toFixed }}
        </template>
      </el-table-column>
      <el-table-column label="得分率" prop="scoringAverage" sortable>
        <template v-slot="{ row }">
          {{ row.scoringAverage | toFixed }}
        </template>
      </el-table-column>
      <el-table-column label="用时" prop="timeConsuming" sortable>
        <template v-slot="{ row }">
          {{ row.timeConsuming | timer }}
        </template>
      </el-table-column>
      <el-table-column label="是否及格" prop="jgStatus"></el-table-column>
      <el-table-column label="排名" prop="ranking" sortable></el-table-column>
    </JADP-table>
    <pagination
      :total="total"
      :page.sync="listQuery.currentPage"
      :limit.sync="listQuery.pageSize"
      @pagination="initData"
    />
  </div>
</template>
<script>
import request from "@/utils/request";
import eventBus from "./eventBus.js";
export default {
  name: "Personnel",
  props: {
    query: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      },
      list: []
    };
  },
  methods: {
    initData() {
      let _query = {
        ...this.listQuery,
        ...this.query,
        organizeId:this.$store.getters.organizeId
      };
      let query = {};
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join();
        } else {
          query[key] = _query[key];
        }
      }
      request({
        url: "/api/statistics/StatisticsController/StudentAnalysis",
        method: "get",
        data: query
      }).then(res => {
        this.list = res.data.list;
        this.total = res.data.pagination.total;
        eventBus.$emit("getList", this.list);
      });
    }
  },
  filters: {
    toFixed(val) {
      return (val * 100).toFixed(1) + "%";
    },
    timer(val) {
      if (val < 60) {
        return val + "秒";
      } else if (val < 3600) {
        return (val / 60).toFixed(0) + "分" + (val % 60) + "秒";
      } else {
        return (
          (val / 3600).toFixed(0) +
          "时" +
          ((val - 3600) / 60).toFixed(0) +
          "分" +
          ((val - 3600) % 60) +
          "秒"
        );
      }
    }
  }
};
</script>
<style scoped lang="scss"></style>
